<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>帮帮网</title>
<link href="../default.css" media="screen" rel="stylesheet" />
<link href="CSS/formStyle.css" rel="stylesheet"  type="text/css" />
<link href="../CSS/kakassiStyle.css" rel="stylesheet"  type="text/css" />
<script type="text/javascript"  src="../JS/prototype.js"></script>
<script type="text/javascript" src="../JS/httpRequest.js"></script>
<script type="text/javascript" src="../JS/cookie.js"></script>
<script type="text/javascript">
//为了兼容ie 创建全局变量
var helpid;
var username;
var userID;
var admincheck;
var status;
var chooseID;
var chooseName;

function showHelp()
{
	//获取help id
	
	var contentURL = document.location.search;
	//body onload调用的函数 所以计算几个全局变量
	helpid = contentURL.slice(1);	//helpid
	username=getCookie('username'); //username
	userID = getCookie('userID');	//userID
	
	//alert(username);
	//alert(userID);

	var url="help.php?action=getHelp";
	var para="&id="+helpid;
	var resp=SendPostRequest(url,para);
	//alert(resp);
	eval("helpinfo="+resp);

	//首先计算全局变量 admincheck status chooseID
	//alert(helpinfo.userID);
	if(userID==helpinfo.userID)
	{
		admincheck = true;
	}
	else
	{
		admincheck = false;
	}
	status = helpinfo.status;
	chooseID = helpinfo.chooseID;

	//然后动态生成页面元素
	var titleDiv=document.getElementById('titleDiv');
	titleDiv.innerHTML = "标题  "+helpinfo.title;

	var moneyDiv=document.getElementById('moneyDiv');
	moneyDiv.innerHTML = "目标赏金  "+helpinfo.money;

	var requestorDiv=document.getElementById('requestorDiv');
	//requestorDiv.innerHTML = "发布者 <img width=50 height=50 src='../imgpick/uploads/"+helpinfo.userID+"'/>"+helpinfo.requesterName;
	if(admincheck==true)
	{
		requestorDiv.innerHTML = "发布者 <a href='../myspace.htm'><img width=50 height=50 src='../imgpick/uploads/"+helpinfo.userID+"'/>"+helpinfo.requesterName+"</a>";		
	}
	else
	{
		requestorDiv.innerHTML = "发布者 <a href='../hisSpace.htm?"+helpinfo.userID+"'><img width=50 height=50 src='../imgpick/uploads/"+helpinfo.userID+"'/>"+helpinfo.requesterName+"</a>";		
	}
	var cateDiv=document.getElementById('cateDiv');
	cateDiv.innerHTML = "类别" + helpinfo.cate;

	var descriptionDiv=document.getElementById('descriptionDiv');
	descriptionDiv.innerHTML = "简介" + helpinfo.description;

	var detailDiv=document.getElementById('detailDiv');
	detailDiv.innerHTML = "详情" + helpinfo.detail;
	
	var statusDiv=document.getElementById('statusDiv');
	statusDiv.innerHTML = "状态  " + helpinfo.status;

	var statusstrDiv=document.getElementById('statusstrDiv');
	statusstrDiv.innerHTML = "状态描述  " + helpinfo.statusstr;
	
	var chooseNameDiv=document.getElementById('chooseNameDiv');
	//chooseNameDiv.innerHTML = "接收人  <img width=50 height=50 src='../imgpick/uploads/"+helpinfo.chooseID+"'/>" + helpinfo.chooseName;
	if(helpinfo.chooseID==0)
	{
		//alert(0);
		chooseNameDiv.innerHTML = "暂时无人承接";
	}
	else if(userID==helpinfo.chooseID)
	{
		chooseNameDiv.innerHTML = "承接者 <a href='../myspace.htm'><img width=50 height=50 src='../imgpick/uploads/"+helpinfo.chooseID+"'/>"+helpinfo.chooseName+"</a>";		
	}
	else
	{
		chooseNameDiv.innerHTML = "承接者 <a href='../hisSpace.htm?"+helpinfo.chooseID+"'><img width=50 height=50 src='../imgpick/uploads/"+helpinfo.chooseID+"'/>"+helpinfo.chooseName+"</a>";		
	}

	var ScoreReqDiv=document.getElementById('ScoreReqDiv');	
	var ScoreChooseDiv=document.getElementById('ScoreChooseDiv');
	ScoreReqDiv.innerHTML = "";
	ScoreChooseDiv.innerHTML = "";
	if(status==3)
	{	
		if(helpinfo.flagScoreReq == 0 )//如果还没有对req评分 显示未打分 如果是chooseID 则给出打分模块
		{
			ScoreReqDiv.innerHTML = "发布人还没有被评分";
			if(userID==helpinfo.chooseID)
			{
				ScoreReqDiv.innerHTML += "  <input type='button' id='ScoreReqButton' style='14px bold' value='我要对发布者打分' onclick='showScoreReq()'>  ";
			}
		}
		else
		{//如果已打分 显示出分数
			ScoreReqDiv.innerHTML = "发布人所得分数  " + helpinfo.ScoreReq;		
		}

		if(helpinfo.flagScoreChoose == 0 )//如果还没有对req评分 显示未打分 如果是chooseID 则给出打分模块
		{
			ScoreChooseDiv.innerHTML = "接收人还没有被评分 ";
			if(userID==helpinfo.userID)
			{
				ScoreChooseDiv.innerHTML += "  <input type='button' id='ScoreChooseButton' style='14px bold' value='我要对承接者打分' onclick='showScoreChoose()'>  ";
			}
		}
		else
		{//如果已打分 显示出分数
			ScoreChooseDiv.innerHTML = "承接人所得分数  " + helpinfo.ScoreChoose;		
		}
	}
	//
	//ScoreChooseDiv.innerHTML = "接收人  " + helpinfo.chooseName;

	//我要评论				
	var commentButton=document.getElementById('commentButton');
	commentButton.innerHTML ="<input type='button' id='commentButtonDiv' style='14px bold' value='我要评论' onclick='showComment()'>";

	var controlDiv=document.getElementById('controlDiv');
	//刷新help信息 要动态加载controlDiv子节点 先清空
	var childs = controlDiv.childNodes;
	for(var i=childs.length-1; i>=0; i--){
		controlDiv.removeChild(childs[i]);
	}

	if(admincheck==false && status!=3 && username!=helpinfo.chooseName )
	{
		//我要申请
		var  applyDiv=document.createElement('div');
		applyDiv.style.padding="10px";
		applyDiv.innerHTML="<input type='button' id='applyDiv' style='14px bold' value='我要申请' onclick='apply()'>";				
		controlDiv.appendChild(applyDiv);			 
	}

	if(admincheck==false && status==1 && username==helpinfo.chooseName && username!=null && username!="")
	{
		//我要确认
		var  confirmDiv=document.createElement('div');
		confirmDiv.style.padding="10px";
		confirmDiv.innerHTML="<input type='button' id='confirmDiv' style='14px bold' value='我要确认' onclick='confirm()'>";				
		controlDiv.appendChild(confirmDiv);
		//我要拒绝
		var  refuseDiv=document.createElement('div');
		refuseDiv.style.padding="10px";
		refuseDiv.innerHTML="<input type='button' id='refuseDiv' style='14px bold' value='我要拒绝' onclick='refuse()'>";				
		controlDiv.appendChild(refuseDiv);
	}

	if(admincheck==true && status==1)
	{
		//我可以解锁  因为我是发布人 且此贴处于状态1  锁给某人 但该人未曾接受
		var  cancelDiv=document.createElement('div');
		cancelDiv.style.padding="10px";
		cancelDiv.innerHTML="<input type='button' id='cancelDiv' style='14px bold' value='我要反悔我的选择' onclick='cancel()'>";				
		controlDiv.appendChild(cancelDiv);
	}

	showCommentList();
	showApplyList();
}

function showScoreReq()
{
	var showScoreReqDiv=document.getElementById('showScoreReqDiv');
	showScoreReqDiv.style.display="block";
}

function hideScoreReq()
{
	var showScoreReqDiv=document.getElementById('showScoreReqDiv');
	showScoreReqDiv.style.display="none";
}

function scoreReq()
{
	var scoreReq=document.getElementById('scoreReq').value;	
	var url="help.php?action=scoreReq";
	var para="&scoreReq="+scoreReq;
	para +="&helpid="+helpid;
	para +="&chooseID="+userID;
	para +="&chooseName="+username;
	var resp=SendPostRequest(url,para);
	alert(resp);	
    if(resp=="该状态不允许评论发布人")
		alert('该状态不允许评论发布人');
	if(resp=="您已经给发布人打过分")
		alert('您已经给发布人打过分');
 	if(resp=="true")
		alert('评论发布者成功');
	if(resp=="false")
		alert('评论发布者失败');	  
	hideScoreReq();
}

function showScoreChoose()
{
	var showScoreChooseDiv=document.getElementById('showScoreChooseDiv');
	showScoreChooseDiv.style.display="block";
}

function hideScoreChoose()
{
	var showScoreChooseDiv=document.getElementById('showScoreChooseDiv');
	showScoreChooseDiv.style.display="none";
}

function scoreChoose()
{
	var scoreChoose=document.getElementById('scoreChoose').value;	
	var url="help.php?action=scoreChoose";
	var para="&scoreChoose="+scoreChoose;
	para +="&helpid="+helpid;
	para +="&userID="+userID;
	para +="&requesterName="+username;
	var resp=SendPostRequest(url,para);
	alert(resp);	
    if(resp=="该状态不允许评论承接人")
		alert('该状态不允许评论承接人');
	if(resp=="您已经给承接人打过分")
		alert('您已经给承接人打过分');
 	if(resp=="true")
		alert('评论承接者成功');
	if(resp=="false")
		alert('评论承接者失败');	  
	hideScoreChoose();
}


function confirm()
{	
	var url="help.php?action=confirm";
	var para="helpid="+helpid;
	para +="&chooseID="+userID;//userID传过去用于验证 但是我怀疑这个安全性还是不够 最好还是在服务器端有session比较安全
	var resp=SendPostRequest(url,para);
	//alert(resp);
	if(resp=="该任务的状态不处于等待确认的状态 所以你不能确认")
		alert('该任务的状态不处于等待确认的状态 所以你不能确认');		
	if(resp=="true")
		alert('确认成功');
	if(resp=="false")
		alert('确认失败');
	showHelp();
}

function refuse()
{
	var url="help.php?action=refuse";
	var para="helpid="+helpid;
	para +="&chooseID="+userID;//userID传过去用于验证 但是我怀疑这个安全性还是不够 最好还是在服务器端有session比较安全
	var resp=SendPostRequest(url,para);
	//alert(resp);
	if(resp=="该任务的状态不处于等待确认的状态 所以你不能拒绝")
		alert('该任务的状态不处于等待确认的状态 所以你不能拒绝');		
	if(resp=="true")
		alert('拒绝成功');
	if(resp=="false")
		alert('拒绝失败');
	showHelp();
}

function cancel()
{	
	//alert('debug');
	var url="help.php?action=cancel";
	var para="helpid="+helpid;
	para +="&userID="+userID;//userID传过去用于验证 但是我怀疑这个安全性还是不够 最好还是在服务器端有session比较安全
	var resp=SendPostRequest(url,para);
	//alert(resp);
	if(resp=="该任务的状态不处于等待接收的状态 所以你不能反悔")
		alert('该任务的状态不处于等待接收的状态 请刷新任务状态信息');		
	if(resp=="true")
		alert('取消成功');
	if(resp=="false")
		alert('取消失败');
	showHelp();
}

function apply()
{

	if(username==null || username=="" || userID==null || userID=="")
	{
		alert("请先登录");
	}
	else if(helpid==""||helpid==null)
	{
		alert("怎么会找不到helpid呢");
	}
	else
	{
	  var url="help.php?action=apply";
	  var para="&helpid="+helpid;
	  para +="&userID="+userID;
	  para +="&username="+username;
	  var resp=SendPostRequest(url,para);

	  alert(resp);
	  if(resp== "该任务已经被别人成功领取")
		alert('该任务已经被别人成功领取');
	  if(resp== "您已申请过了")
		alert( '您已申请过了');
	  if(resp=="true")
		alert('成功申请 您的活跃度+2 如果你关注了发布人的话 那么你对他的关注度+1');
	  if(resp=="false")
		alert('申请失败');	  
	}	
	showApplyList();
}


function showApplyList()
{
	if(helpid==""||helpid==null)
	{
		alert("找不到helpid");
	}
	var url="help.php?action=applyList";
	var para="&helpid="+helpid;
	var resp=SendPostRequest(url,para);
	//alert(resp);
	
	var applyListDiv=document.getElementById('applyListDiv');

	//刷新前 先清空子节点
	var childs = applyListDiv.childNodes;
	for(var i=childs.length-1; i>=0; i--){
		applyListDiv.removeChild(childs[i]);
	}

	var aListDiv=document.createElement('div');
	aListDiv.style.width="600px";
	aListDiv.style.margin="20px";
	aListDiv.style.border="1px solid #ccc";

	if(resp!=null && resp != 'false' && resp!="[]")
	{
		eval("aList="+resp);
		for(var i=0;i<aList.length;i++)
		{
			//alert("i=  "+i);
			var aDiv=document.createElement('div');
			aDiv.style.width="300px";
			aDiv.style.margin="20px";	
			aDiv.style.border="1px solid #ccc";

			var nameDiv=document.createElement('div');
			nameDiv.style.padding="10px";
			//nameDiv.innerHTML="<img width=50 height=50 src='../imgpick/uploads/"+aList[i].uID+"'/><font style='14px bold'>"+aList[i].uName+"</font>";
			if(userID==aList[i].uID)
			{
				nameDiv.innerHTML = "发布者 <a href='../myspace.htm'><img width=50 height=50	src='../imgpick/uploads/"+aList[i].uID+"'/>"+aList[i].uName+"</a>";		
			}
			else
			{
				nameDiv.innerHTML = "发布者 <a href='../hisSpace.htm?"+aList[i].uID+"'><img width=50 height=50	src='../imgpick/uploads/"+aList[i].uID+"'/>"+aList[i].uName+"</a>";		
			}
			
			if(aList[i].uID==chooseID)//如果申请人被选中了 则在页面上显示这个人已经被选中了
					nameDiv.innerHTML += "<span>  【这人已经被选中了】  </span>";

			aDiv.appendChild(nameDiv);

			//就选这个人的按钮
			if(admincheck==true && (status==0 || status==2 )  )
			{
				//alert('我操嘞');
				var chooseDiv = document.createElement('div');
				chooseDiv.innerHTML="<input uId='"+aList[i].uID+"' uName='"+aList[i].uName+"' type='button' style='border:1px solid #ccc' value='就选这个人了' onclick='choose(this)'/>";
				aDiv.appendChild(chooseDiv);
			}

			aListDiv.appendChild(aDiv)
		}
	}
	else
	{
		aListDiv.innerHTML = "多么可惜啊 暂时还没有人申请 ";
	}
	applyListDiv.innerHTML="申请人列表";
	applyListDiv.appendChild(aListDiv);
}

function choose(obj)
{
	//alert('debug');
	//alert(obj.getAttribute("uId"));
	var url="help.php?action=choose";
	var para = "helpid="+helpid;
	para += "&userID="+userID;
	para += "&username="+username;
	para += "&chooseID="+obj.getAttribute("uId");
	para += "&chooseName="+obj.getAttribute("uName");
	var resp=SendPostRequest(url,para);
	//alert(resp);
	if(resp=="该任务已被指定")
		alert('该任务已被指定 请检查该任务的状态');
	if(resp=="true")
		alert('选择成功');
	if(resp=="false")
		alert('选择失败');	
	showHelp();
}

function showCommentList()
{
	if(helpid==""||helpid==null)
	{
		alert("找不到helpid");
	}
	var url="help.php?action=commentList";
	var para="&helpid="+helpid;
	var resp=SendPostRequest(url,para);
	//alert(resp);
	
	var commentListDiv=document.getElementById('commentListDiv');

	//刷新评论列表 先清空commentListDiv子节点
	var childs = commentListDiv.childNodes;
	for(var i=childs.length-1; i>=0; i--){
		commentListDiv.removeChild(childs[i]);
	}



	var cListDiv=document.createElement('div');
	cListDiv.style.width="600px";
	cListDiv.style.margin="20px";
	cListDiv.style.border="1px solid #ccc";

	if(resp!=null && resp != 'false' && resp!="[]")
	{
		eval("cList="+resp);
		for(var i=0;i<cList.length;i++)
		{
			//alert("i=  "+i);
			var comDiv=document.createElement('div');
			comDiv.style.width="300px";
			comDiv.style.margin="20px";	
			comDiv.style.border="1px solid #ccc";

			var nameDiv=document.createElement('div');
			nameDiv.style.padding="10px";
			//nameDiv.innerHTML="<img width=50 height=50 src='../imgpick/uploads/"+cList[i].uID+"'/><font style='14px bold'>"+cList[i].uName+" 说： </font>";	
			if(userID==cList[i].uID)
			{
				nameDiv.innerHTML = "发布者 <a href='../myspace.htm'><img width=50 height=50	src='../imgpick/uploads/"+cList[i].uID+"'/>"+cList[i].uName+"</a>";		
			}
			else
			{
				nameDiv.innerHTML = "发布者 <a href='../hisSpace.htm?"+cList[i].uID+"'><img width=50 height=50	src='../imgpick/uploads/"+cList[i].uID+"'/>"+cList[i].uName+"</a>";		
			}

			if(cList[i].uID==chooseID)//如果申请人被选中了 则在页面上显示这个人已经被选中了
				nameDiv.innerHTML += "<span>  【这人已经被选中了】  </span>";
			comDiv.appendChild(nameDiv);

			var contentDiv=document.createElement('div');
			contentDiv.style.padding="10px";
			contentDiv.innerHTML="<font style='14px bold'>"+cList[i].comment+"</font>";				
			comDiv.appendChild(contentDiv);

			cListDiv.appendChild(comDiv)
		}
	}
	else
	{
		cListDiv.innerHTML = "多么可惜啊 暂时还没有人评论 ";
	}
	commentListDiv.innerHTML="评论内容列表";
	commentListDiv.appendChild(cListDiv);
}

function showComment()
{
	var commentDiv=document.getElementById('commentDiv');
	commentDiv.style.display="block";
}
function hideComment()
{
	var commentDiv=document.getElementById('commentDiv');
	commentDiv.style.display="none";
}

//发布一个任务
function submitComment()
{
	var comment=document.getElementById('commentContent').value;

	if(username==null || username=="" || userID==null || userID=="")
	{
		alert("请先登录");
	}
	else if(comment==""||comment==null)
	{
		alert("评论内容不要为空！");
	}
	else
	{
	  var url="help.php?action=submitComment";
	  var para="&helpid="+helpid;
	  para +="&userID="+userID;
	  para +="&username="+username;
	  para +="&comment="+comment;
	  var resp=SendPostRequest(url,para);

	  //alert(resp);

	  if(resp=="true")
		alert('成功发表评论');
	  if(resp=="false")
		alert('评论失败');	  
	  hideComment();
	}	
	showCommentList();//刷新一下评论列表
}


function CheckEmpty(obj,warnID,warnInfo)
{
	var warnElement=document.getElementById(warnID);
	
	if(obj.value==null || obj.value=="")
	{		
		warnElement.innerText=warnInfo;
		return false;
	}
	else
	{
		warnElement.innerText="OK";
	   return true;
	}
}
</script>

</head>
<body onload="showHelp()">

<div id="all">
    <div id="header">
        <div id="inner_header" class="central_fixed_width">
		    <h1 class="logo">帮帮网</h1>
            <div id="user_status"><a href="../login.htm">登陆</a>||<a href="../register.html">注册</a></div>
            <ul id="nav_bar">
                <li><a href="../activity/activity.html"><span class="nav_item">活动</span></a></li>
                <li><a href="../index.html"><span class="nav_item">悬赏求助大厅</span></a></li>
                <li><a href="../myspace.html"><span class="nav_item">个人主页</span></a></li>
                <li><a href="../dianping.html"><span class="nav_item">点评</span></a></li>
                <li><a href="../novel.html"><span class="nav_item">小说</span></a></li>
                <li class="clear"></li>
            </ul>
        </div>
    </div>
        
	<div id="content" class="central_fixed_width">

		<div id='helpinfoDiv' style="padding:20px;">
			需求信息
			<div id='titleDiv'>    </div>
			<div id='moneyDiv'>    </div>
			<div id='requestorDiv'>    </div>
			<div id='cateDiv'>    </div>
			<div id='descriptionDiv'>    </div>
			<div id='detailDiv'>    </div>
			<div id='statusDiv'>    </div>
			<div id='statusstrDiv'>    </div>
			<div id='chooseNameDiv'>    </div>
			<div id='ScoreReqDiv'>   </div>
			<div id='ScoreChooseDiv'>   </div>
			<div id='commentButton'>   </div>
			<div id='controlDiv'>    </div>
		</div>
		<div class="clear"></div>
		<div id='commentListDiv' style="padding:20px;">评论内容列表</div>
		<div id='applyListDiv' style="padding:20px;">申请人列表</div>

		<div id="showScoreReqDiv" style="width:500px; display:none; position:absolute; z-index:101; left:150px; top:50px; background-color:#2EFE2E; padding:10px;">
		<div>给发布者打分</div>
		<div>
			类别:<select id="scoreReq">
				<option value=-4 > -4 </option>
				<option value=-3 > -3 </option>
				<option value=-2 > -2 </option>
				<option value=-1 > -1 </option>
				<option value=0 > 0 </option>
				<option value=1 > 1 </option>
				<option value=2 > 2 </option>
				<option value=3 > 3 </option>
				<option value=4 > 4 </option>
				</select><br>
		</div>
		<input type="button" value="确定" onclick="scoreReq()"/>    
		<input type="button" value="取消" onclick="hideScoreReq()"/>
		</div>

		<div id="showScoreChooseDiv" style="width:500px; display:none; position:absolute; z-index:101; left:150px; top:50px; background-color:#2EFE2E; padding:10px;">
		<div>给发布者打分</div>
		<div>
			类别:<select id="scoreChoose">
				<option value=-4 > -4 </option>
				<option value=-3 > -3 </option>
				<option value=-2 > -2 </option>
				<option value=-1 > -1 </option>
				<option value=0 > 0 </option>
				<option value=1 > 1 </option>
				<option value=2 > 2 </option>
				<option value=3 > 3 </option>
				<option value=4 > 4 </option>
				</select><br>
		</div>
		<input type="button" value="确定" onclick="scoreChoose()"/>    
		<input type="button" value="取消" onclick="hideScoreChoose()"/>
		</div>

		<div id="commentDiv" style="width:500px; display:none; position:absolute; z-index:101; left:150px; top:50px; background-color:#2EFE2E; padding:10px;">
		<div>发表评论</div>
		<div>
			评论内容:<br><textarea id="commentContent"  rows="15" cols="50" onblur="CheckEmpty(this,'warnCommentContent','具体内容不能为空！')"  ></textarea>
		<span id="warnCommentContent" class="warning">&nbsp;*</span><br>
			<br>
			<input type="button" value="确定" onclick="submitComment()"/>    
			<input type="button" value="取消" onclick="hideComment()"/>
			</div>
		</div>
	
	</div>


    <div id="footer">
        <div id="inner_footer" class="central_fixed_width">


            <div class="footer_links">
                &copy; 2011 帮帮网 All rights reserved.
            </div>
            <div class="clear"></div>
            
        </div>
    </div>
</div>

</body>
</html>